/// @tags:
#include <cstdio>
#include <functional>
#include <iostream>
#include <numeric>
#include <queue>

using std::cin, std::cout, std::endl;

namespace BlueQuantum {

typedef long long ll;

constexpr int maxn = 2e5 + 2;

int a[maxn];
ll sum[maxn];

int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; ++i) {
      cin >> a[i];
      sum[i] = sum[i - 1] + a[i];
    }
    std::priority_queue<int> s;
    ll tmp = sum[m];
    s.push(a[m]);
    int ans = 0;
    for (int i = m - 1; i >= 1; --i) {
      if (sum[i] < tmp) {
        tmp -= 2 * s.top();
        s.pop();
        ++ans;
      }
      s.push(a[i]);
    }
    std::priority_queue<int, std::vector<int>, std::greater<int>> ss;
    tmp = sum[m];
    ll shift = 0;
    for (int i = m + 1; i <= n; ++i) {
      ss.push(a[i]);
      if (sum[i] + shift < tmp) {
        shift += -2 * ss.top();
        ss.pop();
        ++ans;
      }
    }
    cout << ans << '\n';
  }
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("C. Least Prefix Sum.in", "r", stdin);
  freopen("C. Least Prefix Sum.out", "w", stdout);
#endif
#endif

  std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
